<?php 
require_once 'constantes_bd.inc';

$pdo=null;
	if ($pdo == null)
		{
			$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
			$pdo = new PDO("mysql:host=".constantes_bd::$BD_SERVER.";dbname=".constantes_bd::$BD_NAME, constantes_bd::$BD_USER, constantes_bd::$BD_PWD);
		}
	
	if (isset($_GET['num'])){
		$num_photo = $_GET['num'];
	}
	else {
		$num_photo = 0;
	}
	
	if(isset($_GET['instrument'])&& (isset($_GET['categorie']))){
		$i = $_GET['instrument']; 
		$categorie = $_GET['categorie'];
		$r  = "select * from ".$categorie."_photo where instrument =".$i.";" ;
		
		$reponse = $pdo->query($r);
		$nbReponse = $reponse->rowCount();
		if ($nbReponse > 0)
		{
			$array = array();
			while ($donnees = $reponse->fetch())
			{
				$array[] = $donnees;
			}
		
			$donnees = $array[$num_photo];
			if($donnees['image']){
				$image = $donnees['image']; 
				$format = $donnees['format'];
				header("Content-type: ".$format);
				header("Content-transfer-encoding: binary");
				echo $image;
			}
			else {
				echo "pas d'image";
			}
		}
	}
	
?>